if test $# -ne 2
then
    echo useage: gettext.sh locale qucRootPath
    echo     eg: gettext.sh zh_CN /usr/local/www/quc
exit
fi

LANG=$1
ROOT_PATH=$2

if [ ! -d "$ROOT_PATH" ]
then
    echo $ROOT_PATH is not exist.
    exit;
fi

cd $ROOT_PATH

LOCALE=$ROOT_PATH/locale/$LANG

if [ ! -d "$LOCALE" ]
then
    echo $LOCALE is not exist.
    exit;
fi

cd $LOCALE/LC_MESSAGES

#add your all pages which contain charactors here
FILE_LIST="$ROOT_PATH/application/controllers/*.php $ROOT_PATH/exceptions/*.php $ROOT_PATH/application/models/*.php $ROOT_PATH/application/models/accounts/*.php $ROOT_PATH/application/views/helpers/*.php"

if [ -e "messages.mo" ]
then
    rm -f messages.mo
fi

if [ -e "messages.po" ]
then
    xgettext -L php $FILE_LIST -o tmp.po
    mv messages.po old.po
    msgmerge -o messages.po old.po tmp.po
    rm -f old.po tmp.po
else
    xgettext -L php $FILE_LIST
fi

msgfmt messages.po
